
package br.com.fatecpg.tp1.formularios;
/**
 *
 * @author Adilson Alves Feitoza e jean Muniz
 */

public class CalculadoraMassa extends javax.swing.JInternalFrame {


    public CalculadoraMassa() {
        initComponents();
    }
    void  calculaResultado() {
      try {
        double a = DeComboBox.getSelectedIndex();
        double  fator1 = 0 , fator2 =0 , res ;
	if (a==0) fator1 = 1000;
        if (a==1) fator1 = 101.93;
        if (a==2) fator1 = 1;
        if (a==3) fator1 = 0.1;
	if (a==4) fator1 = 0.001;
	if (a==5) fator1 = 0.0002;
        if (a==6) fator1 = 0.00001;
        if (a==7) fator1 = 0.000001;
        if (a==8) fator1 = 0.4535924;
        if (a==9) fator1 = 0.02834954;
	if (a==10)fator1 = 0.373241;
	if (a==11)fator1 = 0.031103;	
	
	a = ParaComboBox.getSelectedIndex();
	
        if (a==0) fator2 = 1000;
        if (a==1) fator2 = 101.93;
        if (a==2) fator2 = 1;
        if (a==3) fator2 = 0.1;
	if (a==4) fator2 = 0.001;
	if (a==5) fator2 = 0.0002;
        if (a==6) fator2 = 0.00001;
        if (a==7) fator2 = 0.000001;
        if (a==8) fator2 = 0.4535924;
        if (a==9) fator2 = 0.02834954;
	if (a==10) fator2 = 0.373241;
	if (a==11) fator2 = 0.031103;
	

       double unidades = Double.parseDouble(ConverterTextField.getText());
       res = unidades * fator1 / fator2;

        ResultadoLabel.setText(Double.toString(res));
        } catch (Exception ex) {
        ResultadoLabel.setText(" Numero Invalido ");
        }

    }
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        jFileChooser2 = new javax.swing.JFileChooser();
        ConverterLabel = new javax.swing.JLabel();
        DeComboBox = new javax.swing.JComboBox();
        ParaLabel = new javax.swing.JLabel();
        ParaComboBox = new javax.swing.JComboBox();
        ResultadoLabel = new javax.swing.JLabel();
        ConverterTextField = new javax.swing.JTextField();
        converterLabel = new javax.swing.JLabel();
        jFileChooser1 = new javax.swing.JFileChooser();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        setBackground(new java.awt.Color(63, 98, 104));
        setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(51, 204, 255)));
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Massa");

        ConverterLabel.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        ConverterLabel.setForeground(new java.awt.Color(102, 204, 255));
        ConverterLabel.setText("de:");

        DeComboBox.setFont(new java.awt.Font("Arial", 1, 11));
        DeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tonelada", "Kilonewton", "Quilograma", "Hectograma", "Grama", "Quilate", "Centigrama", "Miligrama", "libra", "onça", "libra troy", "onça troy" }));
        DeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeComboBoxActionPerformed(evt);
            }
        });

        ParaLabel.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        ParaLabel.setForeground(new java.awt.Color(102, 204, 255));
        ParaLabel.setText("Para:");

        ParaComboBox.setFont(new java.awt.Font("Arial", 1, 11));
        ParaComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tonelada", "Kilonewton", "Quilograma", "Hectograma", "Grama", "Quilate", "Centigrama", "Miligrama", "libra", "onça", "libra troy", "onça troy" }));
        ParaComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ParaComboBoxActionPerformed(evt);
            }
        });

        ResultadoLabel.setBackground(new java.awt.Color(255, 255, 255));
        ResultadoLabel.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        ResultadoLabel.setForeground(new java.awt.Color(255, 255, 255));
        ResultadoLabel.setText("Resultado");
        ResultadoLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(51, 204, 255)));

        ConverterTextField.setText("1");
        ConverterTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ConverterTextFieldActionPerformed(evt);
            }
        });
        ConverterTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                ConverterTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                ConverterTextFieldFocusLost(evt);
            }
        });
        ConverterTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                ConverterTextFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                ConverterTextFieldKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ConverterTextFieldKeyTyped(evt);
            }
        });

        converterLabel.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        converterLabel.setForeground(new java.awt.Color(102, 204, 255));
        converterLabel.setText("Quero converter");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ConverterLabel)
                    .addComponent(ParaLabel)
                    .addComponent(converterLabel)
                    .addComponent(DeComboBox, 0, 261, Short.MAX_VALUE)
                    .addComponent(ConverterTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
                    .addComponent(ParaComboBox, 0, 261, Short.MAX_VALUE)
                    .addComponent(ResultadoLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(converterLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ConverterTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ConverterLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(DeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addComponent(ParaLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ParaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ResultadoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(43, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleName("CalculadoraMassa");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ConverterTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConverterTextFieldActionPerformed
     calculaResultado();
    }//GEN-LAST:event_ConverterTextFieldActionPerformed

    private void ParaComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ParaComboBoxActionPerformed
     calculaResultado();
    }//GEN-LAST:event_ParaComboBoxActionPerformed

    private void DeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeComboBoxActionPerformed
       calculaResultado();
    }//GEN-LAST:event_DeComboBoxActionPerformed

    private void ConverterTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ConverterTextFieldFocusLost
       calculaResultado();
    }//GEN-LAST:event_ConverterTextFieldFocusLost

    private void ConverterTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ConverterTextFieldFocusGained
      calculaResultado();
    }//GEN-LAST:event_ConverterTextFieldFocusGained

    private void ConverterTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ConverterTextFieldKeyPressed
        calculaResultado();
    }//GEN-LAST:event_ConverterTextFieldKeyPressed
    private void ConverterTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ConverterTextFieldKeyTyped
      
    }//GEN-LAST:event_ConverterTextFieldKeyTyped

    private void ConverterTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ConverterTextFieldKeyReleased
        calculaResultado();
    }//GEN-LAST:event_ConverterTextFieldKeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel ConverterLabel;
    private javax.swing.JTextField ConverterTextField;
    private javax.swing.JComboBox DeComboBox;
    private javax.swing.JComboBox ParaComboBox;
    private javax.swing.JLabel ParaLabel;
    private javax.swing.JLabel ResultadoLabel;
    private javax.swing.JLabel converterLabel;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JFileChooser jFileChooser2;
    // End of variables declaration//GEN-END:variables

}
